package com.yidu.StockControl.service.impl;

import com.yidu.StockControl.entity.TAInventory;
import com.yidu.StockControl.mapper.TAInventoryMapper;
import com.yidu.StockControl.service.TAInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TAInventoryServiceImpl implements TAInventoryService {
    @Resource
    TAInventoryMapper taInventoryMapper;


    @Override
    public List<TAInventory> selectTAInventory(String statisticsDate, String fundId, int page, int limit) {
        System.out.println("查询");
        Map map = new HashMap();
        map.put("strWhere",buildWhere(statisticsDate,fundId));
        map.put("page",(page-1)*limit);
        map.put("limit",page*limit);
        return taInventoryMapper.selectTAInventory(map);
    }
    public String buildWhere (String statisticsDate,String fundId) {
        StringBuffer strWhere = new StringBuffer();

        if (statisticsDate!=null && !statisticsDate.equals("")){
            strWhere.append(" and statisticsDate like '%" + statisticsDate +"%'" );
        }
        if (fundId!=null && !fundId.equals("")){
            strWhere.append(" and fundId like '%" + fundId +"%'" );
        }
        return strWhere.toString();
    }

    @Override
    public int insertTAInventory(TAInventory taInventory) {
        return taInventoryMapper.insertTAInventory(taInventory);
    }

    @Override
    public void updateTAInventory(TAInventory taInventory) {
       taInventoryMapper.updateTAInventory(taInventory);
    }

    @Override
    public void deleteTAInventory(String taInventoryId) {
        taInventoryMapper.deleteTAInventory(taInventoryId);
    }

    @Override
    public int selectTAInventoryCount() {
        return taInventoryMapper.selectTAInventoryCount();
    }


}
